From: Keir Fraser Date: Wed, 12 May 2010 07:52:59 +0000 (+0100) Subject: xl: Add command 'xl mem-max' X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~12184 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks://%22Dat/%22http:/www.example.com/cgi/%22https:/%22bookmarks:/%22Dat?a=commitdiff_plain;h=bf4215becc69225e4978582b4210485837f73754;p=xen.git xl: Add command 'xl mem-max' Add subcommand 'xl mem-max', can be used to set static max memory Signed-off-by: Yu Zhiguo --- diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index e031582083..176ea89af3 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2346,6 +2346,39 @@ int libxl_device_pci_shutdown(struct libxl_ctx *ctx, uint32_t domid) return 0; } +int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t max_memkb) +{ + char *mem, *endptr; + uint32_t memorykb; + char *dompath = libxl_xs_get_dompath(ctx, domid); + int rc; + + mem = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/memory/target", dompath)); + if (!mem) { + XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "cannot get memory info from %s/memory/target\n", dompath); + return 1; + } + memorykb = strtoul(mem, &endptr, 10); + if (*endptr != '\0') { + XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "invalid memory %s from %s/memory/target\n", mem, dompath); + return 1; + } + + if (max_memkb < memorykb) { + XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "memory_static_max must be greater than or or equal to memory_dynamic_max\n"); + return 1; + } + + rc = xc_domain_setmaxmem(ctx->xch, domid, max_memkb); + if (rc != 0) + return rc; + + if (domid != 0) + libxl_xs_write(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/memory/static-max", dompath), "%lu", max_memkb); + + return rc; +} + int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb) { int rc = 0; diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index ffed896f45..5d300c6aca 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -339,6 +339,7 @@ int libxl_domain_rename(struct libxl_ctx *ctx, uint32_t domid, int libxl_domain_pause(struct libxl_ctx *ctx, uint32_t domid); int libxl_domain_unpause(struct libxl_ctx *ctx, uint32_t domid); +int libxl_domain_setmaxmem(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb); int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb); int libxl_console_attach(struct libxl_ctx *ctx, uint32_t domid, int cons_num); diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index ddb0bfd132..e9a98a819d 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1187,6 +1187,59 @@ void help(char *command) } } +int set_memory_max(char *p, char *mem) +{ + char *endptr; + uint32_t memorykb; + int rc; + + find_domain(p); + + memorykb = strtoul(mem, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, "invalid memory size: %s\n", mem); + exit(3); + } + + rc = libxl_domain_setmaxmem(&ctx, domid, memorykb); + + return rc; +} + +int main_memmax(int argc, char **argv) +{ + int opt = 0; + char *p = NULL, *mem; + int rc; + + while ((opt = getopt(argc, argv, "h")) != -1) { + switch (opt) { + case 'h': + help("mem-max"); + exit(0); + default: + fprintf(stderr, "option not supported\n"); + break; + } + } + if (optind >= argc - 1) { + help("mem-max"); + exit(2); + } + + p = argv[optind]; + mem = argv[optind + 1]; + + rc = set_memory_max(p, mem); + if (rc) { + fprintf(stderr, "cannot set domid %d static max memory to : %s\n", domid, mem); + exit(1); + } + + printf("setting domid %d static max memory to : %s\n", domid, mem); + exit(0); +} + void set_memory_target(char *p, char *mem) { char *endptr; diff --git a/tools/libxl/xl_cmdimpl.h b/tools/libxl/xl_cmdimpl.h index 3c7b9fd1f6..6f2a1fa657 100644 --- a/tools/libxl/xl_cmdimpl.h +++ b/tools/libxl/xl_cmdimpl.h @@ -33,6 +33,7 @@ int main_create(int argc, char **argv); int main_button_press(int argc, char **argv); int main_vcpupin(int argc, char **argv); int main_vcpuset(int argc, char **argv); +int main_memmax(int argc, char **argv); int main_memset(int argc, char **argv); int main_sched_credit(int argc, char **argv); int main_domid(int argc, char **argv); diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index 3609e1b93f..5d3cea3250 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -108,6 +108,11 @@ struct cmd_spec cmd_table[] = { "Eject a cdrom from a guest's cd drive", " ", }, + { "mem-max", + &main_memmax, + "Set the maximum amount reservation for a domain", + " ", + }, { "mem-set", &main_memset, "Set the current memory usage for a domain",